<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.bootcss.com/animate.css/3.7.2/animate.min.css" id="style0" rel="stylesheet">
    <link href="https://cdn.bootcss.com/Swiper/4.5.1/css/swiper.min.css" id="style1" rel="stylesheet">
    <script src="https://cdn.bootcss.com/Swiper/4.5.1/js/swiper.min.js" id="swiper" type="text/javascript"
        charset="utf-8"></script>
</head>

<body>
    <!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <p class="ani"
                    swiper-animate-effect='[{"value":"fadeInRight","duration":1,"loop":1,"delay":0},{"value":"fadeInLeft","duration":1,"loop":2,"delay":0}]'>
                    slider1</p>
            </div>
            <div class="swiper-slide">
                <p class="ani"
                    swiper-animate-effect='[{"value":"fadeInRight","duration":1,"loop":1,"delay":0},{"value":"fadeInLeft","duration":1,"loop":1,"delay":0}]'>
                    slider2</p>
            </div>

            <div class="swiper-slide">
                <p class="ani"
                    swiper-animate-effect='[{"value":"fadeInRight","duration":1,"loop":1,"delay":0},{"value":"fadeInLeft","duration":1,"loop":1,"delay":0}]'>
                    slider3</p>
            </div>

        </div>
    </div>
    <script src="./swiper.animate.js"></script>
    <script>
        let mySwiper = new Swiper('.swiper-container', {
            on: {
                init() {
                    window.swiperAnimate(this);

                },
                slideChangeTransitionEnd() {
                    window.swiperAnimate(this);
                }
            }
        });
        // 动态设置动画
        let ani = [{
            "value": "fadeInRight",
            "duration": 1,
            "loop": 1,
            "delay": 0
        }, {
            "value": "fadeInLeft",
            "duration": 1,
            "loop": 1,
            "delay": 0
        }, {
            "value": "fadeIn",
            "duration": 1,
            "loop": 0,
            "delay": 0
        }, ];
        for (let i = 0; i < 3; i++) {
            let div = document.createElement('div');
            let p = document.createElement('p');
            p.innerText = '这是一个新的Slide';
            p.className = 'ani';
            p.setAttribute('swiper-animate-effect', JSON.stringify(ani));
            div.appendChild(p);
            div.className = 'swiper-slide';
            mySwiper.addSlide(1, div);
            mySwiper.updateSlides();
        }
    </script>
</body>

</html>
